package com.cpi.cornpp.customerpurchase.view;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.cpi.cornpp.common.view.IBaseView;
import com.cpi.cornpp.customer.view.CustomerView;
import com.cpi.cornpp.productpurchase.view.ProductPurchaseView;
import com.cs.common.utils.StringUtils;

public class CustomerPurchaseView extends CustomerView implements IBaseView {
	
	private static final long serialVersionUID = -6059696864285015185L;
	
	private int futureDistributionId;
	private int futureId;
	private String customerId;
	private String futureTypeId;
	private int quantity;
	private int quantityFixed;
	private int quantityDirect;	
	private Boolean selected;
	private boolean removed;
	private List resultProducts;
	
	/**
	 *Lista de productos seleccionados del resultado 
	 */
	private String[] selectedProductIds = {}; 
	
	/**
	 *Lista de productos removidos del resultado 
	 */
	private String[] removedProductIds = {}; 
		
	
	private List productPurchaseViews;

	public CustomerPurchaseView() {
		productPurchaseViews = new ArrayList(0);		
	}
		
	public int getFutureDistributionId() {
		return futureDistributionId;
	}
	public void setFutureDistributionId(int aCupId) {
		futureDistributionId = aCupId;
	}
	public int getFutureId() {
		return futureId;
	}
	public void setFutureId(int aCupFutureId) {
		futureId = aCupFutureId;
	}
	public String getCustomerId() {
		return this.customerId;
		
	}
	public void setCustomerId(String aCupCustomerId) {		
		customerId = aCupCustomerId;
	}
	public String getFutureTypeId() {
		return futureTypeId;
	}
	public void setFutureTypeId(String aCupFutureTypeId) {
		futureTypeId = aCupFutureTypeId;
	}
	public int getQuantity() {
		return quantity;
	}
	public void setQuantity(int aCupQuantity) {
		quantity = aCupQuantity;
	}	
	public int getQuantityDirect() {
		return quantityDirect;
	}
	public void setQuantityDirect(int quantityDirect) {
		this.quantityDirect = quantityDirect;
	}
	public int getQuantityFixed() {
		return quantityFixed;
	}
	public void setQuantityFixed(int quantityFixed) {
		this.quantityFixed = quantityFixed;
	}
	public List getProductPurchaseViews() {
		return productPurchaseViews;
	}
	
	public String getProductPurchaseViewsCSV() {
		StringBuffer sb = new StringBuffer(0);
		ProductPurchaseView ppView = null;
		Iterator iterator = this.productPurchaseViews.iterator();
		while( iterator.hasNext() ){
			ppView = (ProductPurchaseView)iterator.next();
			sb.append(ppView.getProductId());
			sb.append(StringUtils.SPACE_CHAR);
			sb.append(StringUtils.LEFT_PARENTHESIS);
			sb.append(ppView.getQuantity());
			sb.append(StringUtils.RIGHT_PARENTHESIS);
			if(iterator.hasNext())
				sb.append(StringUtils.COMMA);
		}
		return sb.toString();
		
	}
	
	public void setProductPurchaseViews(
			List productPurchaseViews) {
		this.productPurchaseViews = productPurchaseViews;
	}
	
	public Boolean getSelected() {
		return selected;
	}
	public void setSelected(Boolean currentSelected) {
		this.selected = currentSelected;
	}

	public String[] getSelectedProductIds() {
		return selectedProductIds;
	}
	public void setSelectedProductIds(String[] selectedProductIds) {
		this.selectedProductIds = selectedProductIds;
	}	
	
	public String[] getRemovedProductIds() {
		return removedProductIds;
	}

	public void setRemovedProductIds(String[] removedProductIds) {
		this.removedProductIds = removedProductIds;
	}

	public List getResultProducts() {
		return resultProducts;
	}
	public void setResultProducts(List resultProducts) {
		this.resultProducts = resultProducts;
	}

	public boolean equals(Object obj) {
		if(!(obj instanceof CustomerPurchaseView))
			return false;
		CustomerPurchaseView cus = (CustomerPurchaseView)obj;
		if( this.getCustomerId() == null ){
			this.setCustomerId("");
		}
		return this.getCustomerId().trim().equals(cus.getCustomerId().trim()); 		
	}
	
	public int getProductPurchaseViewsSize(){
		if(productPurchaseViews!=null){
			return productPurchaseViews.size();
		}else{
			return 0;
		}
	}

	public boolean isRemoved() {
		return removed;
	}

	public void setRemoved(boolean removed) {
		this.removed = removed;
	}
	
	
}